﻿using System;
using System.Collections.Generic;
using System.Linq;
#if !NETCOREAPP
using System.Web;
using System.Web.Mvc;
using System.Web.WebPages;
    using System.Web.Mvc.Html;

#endif

#if NETCOREAPP
using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.AspNetCore.Mvc.Rendering;
using Kugar.Core.Web;
#endif
using Kugar.Core.ExtMethod;
using Kugar.MVC.MobileUI.WeUI.Helpers;

namespace Kugar.MVC.MobileUI.WeUI.PageControls.PageCommons
{
    public class PageCommon_Footer:ControlBase
    {
        private List<KeyValuePair<string,string>> _links=new List<KeyValuePair<string, string>>(2);
        private string _text = "";

        public PageCommon_Footer(ViewContext viewContext) : base(viewContext)
        {
            this.Css("weui-footer weui-footer_fixed-bottom");
        }

        public PageCommon_Footer AddLink(string title, string linkUrl)
        {
            _links.Add(new KeyValuePair<string, string>(title,linkUrl));

            return this;
        }

        public PageCommon_Footer Text(string text)
        {
            _text = text;

            return this;
        }
        
        public override MvcHtmlString Render()
        {
            /*
             <div class="weui-footer weui-footer_fixed-bottom">
                <p class="weui-footer__links">
                  <a href="http://jqweui.com" class="weui-footer__link">jQuery-WeUI 首页</a>
                </p>
                <p class="weui-footer__text">Copyright © 2016 jqweui.io</p>
              </div>
             */

            ViewContext.Writer.WriteLine($"<div {_attrs}>");

            if (_links.HasData())
            {
                ViewContext.Writer.WriteLine("<p class=\"weui-footer__links\">");

                foreach (var item in _links)
                {
                    ViewContext.Writer.WriteLine($"<a href=\"{item.Value}\" class=\"weui-footer__link\">{item.Key}</a>");
                }
                
                ViewContext.Writer.WriteLine("</p>");
            }

            ViewContext.Writer.WriteLine($"<p class=\"weui-footer__text\">{_text}</p>");

            ViewContext.Writer.WriteLine("</div> <!-- end  weui-footer-->");
            return MvcHtmlString.Empty;
        }
    }

    public class PageCommon_FooterContainer : ContainerBase
    {
        public PageCommon_FooterContainer(ViewContext viewContext) : base(viewContext)
        {
            this.Css("weui-footer weui-footer_fixed-bottom");
        }

        public override void Dispose()
        {
            ViewContext.Writer.WriteLine("</div> <!-- end  weui-footer-->");
        }

        internal override ContainerBase RenderInternal()
        {
            ViewContext.Writer.WriteLine($"<div {_attrs}>");

            return this;
        }
    }
}